Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check-msrv: Autodetect expected MSRV #429

Merged
merged 2 commits into from
Nov 10, 2024
Merged

check-msrv: Autodetect expected MSRV #429

merged 2 commits into from
Nov 10, 2024

Conversation

magicant
Copy link
Owner

@magicant magicant commented Nov 10, 2024

This commit updates the check-msrv script to autodetect the expected
minimum supported Rust version (MSRV) for each crate. This is done by
querying the rust_version field of the package metadata using jq.
This ensures that the script always tests the correct MSRV for each
crate, even if the MSRV is updated in the future.

Summary by CodeRabbit

  • New Features

    • Introduced a check function to streamline workspace member updates and dynamically retrieve the minimum supported Rust version (MSRV) for packages.
  • Improvements

    • Enhanced control flow and maintainability by consolidating repeated logic within the check function.
    • Updated testing commands to utilize dynamically retrieved MSRV values instead of hardcoded versions.
  • Bug Fixes

    • Improved quiet mode functionality for better control of output based on user input.

This commit updates the `check-msrv` script to autodetect the expected
minimum supported Rust version (MSRV) for each crate. This is done by
querying the `rust_version` field of the package metadata using `jq`.
This ensures that the script always tests the correct MSRV for each
crate, even if the MSRV is updated in the future.
@magicant magicant self-assigned this Nov 10, 2024
Copy link

coderabbitai bot commented Nov 10, 2024

Walkthrough

The check-msrv.sh script has been significantly modified to enhance the testing process for multiple packages. A new check function has been introduced, which encapsulates the logic for updating workspace members and executing tests. This function dynamically retrieves the minimum supported Rust version (MSRV) using cargo metadata, allowing for runtime adaptability. The control flow has been streamlined by consolidating cargo command invocations within the check function, while maintaining the quiet mode functionality for controlled output.

Changes

File Change Summary
check-msrv.sh Introduced check(package, ...options) function; modified update_workspace_member() usage; consolidated cargo commands to use dynamically retrieved MSRV; maintained quiet mode functionality.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Script
    participant Cargo

    User->>Script: Execute check-msrv.sh
    Script->>Script: Call check(package_name)
    Script->>Cargo: Update workspace member
    Cargo-->>Script: Confirm update
    Script->>Cargo: Retrieve MSRV
    Cargo-->>Script: Return MSRV
    Script->>Cargo: Run tests with MSRV
    Cargo-->>Script: Test results
    Script-->>User: Output results
Loading

🐰 "In the script's new dance,
The MSRV prance,
With updates so bright,
We test with delight!
A hop and a skip,
In quiet we sip!" 🥕


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (1)
check-msrv.sh (1)

Line range hint 1-18: Consider enhancing script robustness and maintainability.

While the basic error handling is in place, there are several improvements that could make the script more robust:

  1. Add script documentation explaining its purpose and usage
  2. Add version checking for required tools (cargo, jq)
  3. Consider using command-line argument parsing for better flexibility
  4. Add logging levels for better debugging

Here's a suggested improvement for the script header:

+#!/usr/bin/env bash
+# check-msrv.sh: Test packages against their Minimum Supported Rust Version (MSRV)
+# Usage: ./check-msrv.sh [--verbose]
+
 set -Ceu
 
+# Check required tools
+for cmd in cargo jq git; do
+    if ! command -v "$cmd" >/dev/null 2>&1; then
+        echo "Error: Required command '$cmd' not found" >&2
+        exit 1
+    fi
+done
+
 if [ "$*" = "" ]; then quiet='--quiet'; else quiet=''; fi
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fa4f194 and d93e88f.

📒 Files selected for processing (1)
  • check-msrv.sh (1 hunks)

check-msrv.sh Outdated Show resolved Hide resolved
check-msrv.sh Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
check-msrv.sh (2)

30-31: Consider making the jq query more robust.

While the current query works with set -e, it could be made more robust by providing a fallback value when the rust_version field is missing:

-    msrv=$(cargo metadata --format-version=1 |
-        jq -r ".packages[] | select(.name == \"$package\") | .rust_version")
+    msrv=$(cargo metadata --format-version=1 |
+        jq -r ".packages[] | select(.name == \"$package\") | .rust_version // \"1.70.0\"")

This ensures a sensible default MSRV if the field is missing, while maintaining the script's behavior due to set -e.


38-48: Consider extracting package list for better maintainability.

While the current implementation works well, consider extracting the package list to make it more maintainable:

+# List of packages to test
+packages="yash-arith yash-builtin yash-cli yash-env yash-env-test-helper \
+         yash-executor yash-fnmatch yash-prompt yash-quote yash-semantics"
+
+# Test regular packages
+for package in $packages; do
+    check "$package"
+done
+
+# Test yash-syntax with and without features
+check yash-syntax '' '--features annotate-snippets'

This makes it easier to:

  1. Add or remove packages in the future
  2. See all packages at a glance
  3. Maintain special cases separately
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d93e88f and 05c402f.

📒 Files selected for processing (1)
  • check-msrv.sh (1 hunks)
🔇 Additional comments (3)
check-msrv.sh (3)

19-21: LGTM! Clear and concise function documentation.

The documentation clearly describes the function parameters and their purpose.


22-26: LGTM! Robust parameter handling.

The parameter handling is POSIX-compliant and handles the case of no additional options gracefully.


33-35: LGTM! Clean and POSIX-compliant test execution.

The loop correctly handles multiple test options while maintaining the quiet flag functionality.

@magicant magicant merged commit c732202 into master Nov 10, 2024
8 checks passed
@magicant magicant deleted the check-msrv branch November 10, 2024 04:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant